import requests
from lxml import etree
import re
def get_url():
    result=requests.get("https://cive.sspu.edu.cn/info/iList.jsp?cat_id=10727")
    result.encoding=result.apparent_encoding
    html=etree.HTML(result.text)
    aHref=html.xpath('//*[@id="yb_h"]/div[3]/ul/li/a/@href')
    return aHref
def get_info(url):
    result=requests.get(url)
    result.encoding=result.apparent_encoding
    html=etree.HTML(result.text)
    titles=html.xpath('// *[ @ id = "yb_h" ] / div[ 4 ] / a/text()')
    reTitles=html.xpath('// *[ @ id = "yb_h" ] / div[ 5 ] / a/text()')
    timesinfo=html.xpath('// *[ @ id = "yb_h" ] / div[ 7 ] / span/text()')
    times=re.findall('\d{4}-\d{2}-\d{2}',timesinfo[0])
    newsCon = re.findall('<div class="neirongye_nr">(.*?)</div>',result.text,re.S)[0]
    newsFormat=re.sub ('<.*?>' , '', newsCon)
    newsFormat=re.sub('&nbsp;','',newsFormat)
    if len (reTitles)==0:
        for titles,times in zip(titles,times):
            data={
                'title': titles,
                'time':times,
                'news':newsFormat
            }
    else:
        for titles,reTitles,times in zip(titles,reTitles,times):
            data={
                'title': titles,
                'retitle':reTitles,
                'time':times,
                'news':newsFormat
            }
    return data
def print_info(data):
    for dictkey,dictvalue in data.items():
        print(dictkey,':',dictvalue)

aHref=get_url()
for href in aHref:
    url="https://cive.sspu.edu.cn"+href
    data=get_info(url)
    print_info(data)

